package org.helsoft.mojo.api;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

public class BundleListFileFilter implements FilenameFilter {
	private final List<Bundle> bundles;
	private final boolean anyVersion;
	
	public BundleListFileFilter(List<Bundle> bundles, boolean anyVersion) {
		this.bundles = bundles == null ? new ArrayList<Bundle>() : bundles;
		this.anyVersion = anyVersion;
	}

	public BundleListFileFilter(List<Bundle> bundles) {
		this(bundles, false);
	}
	
	@Override
	public boolean accept(File dir, String name) {
		for (Bundle bundle : bundles) {
			boolean matches = new BundleFileFilter(bundle, anyVersion).accept(dir, name);
			if (matches) {
				return true;
			}
		}
		return false;
	}

}
